{% load staticfiles comments bleach_tags %}
<div class="card card-block">
    {% render_comment_form for post %}
</div>
{% get_comment_count for post as comment_count %}
<h3 class="card-title">评论列表
    <small>({{ comment_count }})</small>
</h3>
{% if comment_count %}
    <ul class="comments-list">
    {% for root_comment in post.root_comments %}
        <li class="single-comment" id="c{{ root_comment.pk }}">
            <div class="comment-box">
                <div class="comment-author">
                    <img src="{% static 'blog/img/default_avatar.jpg' %}" alt="Comment Author" style="width: 50px"/>
                </div>
                <div class="comment-info">
                    <p class="author-name">
                        {% if root_comment.url %}
                            <a href="{{ root_comment.url }}" rel="nofollow">{{ root_comment.name }}
                                {% if root_comment.user.is_superuser %}
                                    <span class="label label-danger">博主</span>
                                {% endif %}</a>
                        {% else %}
                            <span>{{ root_comment.name }}
                                {% if root_comment.user.is_superuser %}
                                    <span class="label label-danger">博主</span>
                                {% endif %}</span>
                        {% endif %}
                    </p>
                    <time class="comment-date"
                          title="{{ root_comment.submit_date }}">{{ root_comment.submit_date |timesince }}前
                    </time>
                    <p>{{ root_comment.comment_html|bleach|safe }}</p>
                    <a href="{% url 'comments:reply' root_comment.pk %}" class="reply-link" title="Reply">回复</a>
                </div>
            </div>
            <ul class="reply">
                {% for desc_comment in root_comment.get_descendants_reversely %}
                    <li class="single-comment" id="c{{ desc_comment.pk }}">
                        <div class="comment-box">
                            <div class="comment-author">
                                <img src="{% static 'blog/img/default_avatar.jpg' %}" alt="Comment Author"
                                     style="width: 50px"/>
                            </div>
                            <div class="comment-info">
                                <p class="author-name">
                                    {% if desc_comment.url %}
                                        <a href="{{ desc_comment.url }}" rel="nofollow">{{ desc_comment.name }}
                                            {% if desc_comment.user.is_superuser %}
                                                <span class="label label-danger">博主</span>
                                            {% endif %}</a>
                                    {% else %}
                                        <span>{{ desc_comment.name }}
                                            {% if desc_comment.user.is_superuser %}
                                                <span class="label label-danger">博主</span>
                                            {% endif %}</span>
                                    {% endif %}
                                    <i class="fa fa-share" aria-hidden="true"></i>
                                    {% if desc_comment.parent.url %}
                                        <a href="{{ desc_comment.parent.url }}"
                                           rel="nofollow">{{ desc_comment.parent.name }}
                                            {% if desc_comment.parent.user.is_superuser %}
                                                <span class="label label-danger">博主</span>
                                            {% endif %}</a>
                                    {% else %}
                                        <span>{{ desc_comment.parent.name }}
                                            {% if desc_comment.parent.user.is_superuser %}
                                                <span class="label label-danger">博主</span>
                                            {% endif %}</span>
                                    {% endif %}
                                </p>
                                <time class="comment-date"
                                      title="{{ desc_comment.submit_date }}">{{ desc_comment.submit_date |timesince }}前
                                </time>
                                <p>{{ desc_comment.comment_html|bleach|safe }}</p>
                                <a href="{% url 'comments:reply' desc_comment.pk %}" class="reply-link"
                                   title="Reply">回复</a>
                            </div>
                        </div>
                    </li><!-- /.single-comment -->
                {% endfor %}
            </ul><!-- /.reply -->
        </li><!-- /.single-comment -->
    {% endfor %}
{% else %}
    暂无评论
{% endif %}
</ul>
